package cn.micro.system.manage.controller;


import cn.micro.system.manage.common.log.annotation.Log;
import cn.micro.system.manage.common.log.enums.BusinessType;
import cn.micro.system.manage.common.result.Result;
import cn.micro.system.manage.entity.AssetDimProductVersion;
import cn.micro.system.manage.entity.dto.UpdateStatusDTO;
import cn.micro.system.manage.service.AssetDimProductInfoService;
import cn.micro.system.manage.service.AssetDimProductVersionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 产品版本信息表 前端控制器
 * </p>
 *
 * @author wr
 * @since 2024-01-05
 */
@RestController
@RequestMapping("/manage/assetDimProductVersion")
@RequiredArgsConstructor
@Validated
public class AssetDimProductVersionController {


    private final AssetDimProductVersionService assetDimProductVersionService;


    @PostMapping("pub")
    @Log(title = "项目版本管理--发布版本", businessType = BusinessType.INSERT)
    public Object pub(@RequestBody AssetDimProductVersion productVersion){
        if (!assetDimProductVersionService.pub(productVersion)){
            return Result.fail();
        }
        return Result.success();
    }


    @PutMapping("updateStatus")
    @Log(title = "项目版本管理--更新版本状态", businessType = BusinessType.INSERT)
    public Object updateStatus(@RequestBody UpdateStatusDTO dto){
        AssetDimProductVersion version = new AssetDimProductVersion();
        version.setId(dto.getId());
        version.setStatus(dto.getStatus());
        if (!assetDimProductVersionService.updateById(version)){
            return Result.fail();
        }
        return Result.success();
    }

    @DeleteMapping("delete/{id}")
    public Object delete(Long id){
        if (!assetDimProductVersionService.removeById(id)){
            return Result.fail();
        }
        return Result.success();
    }


}
